<template>
  <div class="mine-center">
    <Heads types="mine"></Heads>

    <div class="content">
      <div v-if="weatherinfo" class="weather">
        <div>{{weatherinfo.city}}天气</div>
        <p>温度: {{weatherinfo.temp1}}/{{weatherinfo.temp2}}</p>
        <p>类型: {{weatherinfo.weather}}</p>
        <p>日落时间: {{weatherinfo.ptime}}</p>
      </div>
      <div v-else class="weather">
        未查询到天气,抱歉!
      </div>
    </div>

    <van-button @click="exit" class="exit" type="danger" size="large">退出登录</van-button>
  </div>
</template>

<script>
import { mapState, mapMutations } from 'vuex'
export default {
  data () {
    return {
      weatherinfo: null
    }
  },
  computed: {
    ...mapState('cityModule', ['cityId'])
  },
  methods: {
    ...mapMutations('footerModule', ['FOOTERSHOW']),
    exit () {
      sessionStorage.removeItem('userInfo')
      this.$router.push({ name: 'Home' })
    }
  },
  mounted () {
    this.FOOTERSHOW(false)
    fetch(`/data/cityinfo/${this.cityId}.html`)
      .then(res => res.json()).then(res => {
        if (res.weatherinfo) {
          this.weatherinfo = res.weatherinfo
        }
      })
  },
  destroyed () {
    this.FOOTERSHOW(true)
  }
}
</script>

<style lang="scss" scoped>
.mine-center {
  .content {
    .weather{
      margin: .2rem;
      background-color: #fff;
      border-radius: .1rem;
    }
  }
  .exit{
    position: fixed;
    left: 0;
    bottom: 0.5rem;
  }
}
</style>
